package hot100;

import javax.xml.stream.FactoryConfigurationError;
import java.util.Objects;

public class Lc101 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {}

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return this.dfs(root.left, root.right);
    }

    public boolean dfs(TreeNode rootLeft, TreeNode rootRight) {
        if (rootLeft == null && rootRight == null) {
            return true;
        }
        if (rootLeft == null || rootRight == null) {
            return false;
        }
        if (rootLeft.val != rootRight.val) {
            return false;
        }
        return dfs(rootLeft.left, rootRight.right) && dfs(rootLeft.right, rootRight.left);
    }
}
